<%--
  Created by IntelliJ IDEA.
  User: 12
  Date: 2023/3/8
  Time: 16:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%--1. 引入jquery--%>
<script src="/webjars/jquery/3.6.1/jquery.min.js"></script>
<%--2. 引入bootstrap--%>
<link rel="stylesheet" href="/webjars/bootstrap/3.4.1/css/bootstrap.min.css">
<script src="/webjars/bootstrap/3.4.1/js/bootstrap.min.js"></script>
<style>
    .table{
        text-align: center;
    }
    .pagination{
        padding: 0;
        margin: 0;
    }
</style>
<script>
    // 点超链接按钮时跳转到指定页面
    function skipPage(v){
        // 1. 为隐藏表单域赋值
        $("#page").val(v)
        // 2. 提交表单
        document.forms[0].submit()
    }
</script>
<html>
<head>
    <title>学生列表</title>
</head>
<body>
    <div class="container">
        <div class="panel panel-primary">
            <div class="panel-heading">
                <h3 class="panel-title">
                    <h3>学生列表（使用ssm+webjars+bs实现）</h3>
                </h3>
            </div>
            <table class="table table-striped table-hover">
                <tr>
                    <td>学生编号</td>
                    <td>学生姓名</td>
                    <td>学习性别</td>
                    <td>学生年龄</td>
                    <td>学生住址</td>
                    <td>所在班级</td>
                    <td>操作</td>
                </tr>
                <c:forEach items="${pr.rows}" var="stud">
                <tr>
                    <td>${stud.sid}</td>
                    <td>${stud.sname}</td>
                    <td>${stud.sex}</td>
                    <td>${stud.age}</td>
                    <td>${stud.addr}</td>
                    <td>${stud.cname}</td>
                    <td>
                        <a href="/student/editPage.do?sid=${stud.sid}" class="btn btn-danger btn-sm">修改</a>
                        <a href="/student/delete.do?sid=${stud.sid}" onclick="return confirm('你真的要删除该学生嘛！')" class="btn btn-danger btn-sm">删除</a>
                    </td>
                </tr>
                </c:forEach>
            </table>
            <div class="panel-footer text-right">
                <%--条件查询模块--%>
                    <form class="form-inline" style="float: left" method="post" action="/student/search.do">
                        <%--param代表？后面的--%>
                        <input type="hidden" name="page" id="page" value="${param.page}">
                        <div class="form-group">
                            <input type="text" class="form-control" name="sname" value="${student.sname}" id="sname" placeholder="请输入学生姓名">
                        </div>
                        <div class="form-group">
                            <input type="text" class="form-control" name="addr" value="${student.addr}" id="addr" placeholder="请输入学生住址">
                        </div>
                        <div class="form-group">
                            <select class="form-control" name="cid" id="cid">
                                <option value="0">所有班级</option>
                                <c:forEach items="${classes}" var="c">
                                    <option value="${c.cid}" ${c.cid == student.cid ? 'selected' : ''}>${c.cname}</option>
                                </c:forEach>
                            </select>
                        </div>
                        <button type="submit" class="btn btn-sm btn-success">开始查询</button>
                        <a href="/student/editPage.do" class="btn btn-sm btn-danger">添加学生</a>

                    </form>
                <%--分页查询模块--%>
                <nav aria-label="Page navigation">
                    <ul class="pagination">
                        <li>
                            <a href="#" aria-label="Previous">
                                <span aria-hidden="true">&laquo;</span>
                            </a>
                        </li>
                        <c:forEach begin="1" end="${pr.totalPage}" var="p">
                        <li class="${p == pr.page ? "active" : ''}">
                            <a  onclick="skipPage(${p})">${p}</a>
                        </c:forEach>
                        <li>
                            <a href="#" aria-label="Next">
                                <span aria-hidden="true">&raquo;</span>
                            </a>
                        </li>
                    </ul>
                </nav>
            </div>
        </div>
    </div>
</body>
</html>
